<template>
  <div class="login_container">
    <div class="login_box">
      <h2>疫苗接种系统管理端</h2>
      <!-- 登录表单 -->
      <el-form ref="loginFormRef" :model="loginForm" class="login_form" :rules="rules">
        <!-- 用户名 -->
        <el-form-item prop="userId">
          <el-input v-model="loginForm.userId" prefix-icon="iconfont icon-user"></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" prefix-icon="iconfont icon-wodemima" type="password"></el-input>
        </el-form-item>
        <!-- 按钮 -->
        <el-form-item class="btn">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="info" @click="tiao_zhuan">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        // 表单数据
        loginForm: {
          userId: "",
          password: ""
        },
        rules: {
          userId: [{
            required: true,
            message: '用户名不能为空',
            trigger: 'blur'
          }],
          password: [{
            required: true,
            message: '密码不能为空',
            trigger: 'blur'
          }]

        }
      }
    },
    methods: {
      // 重置表单
      resetLoginForm() {
        this.$refs.loginFormRef.resetFields();
      },
      // 登录
      login() {
        this.$refs.loginFormRef.validate(async value => {
          if (!value) return;
          const {
            data: res
          } = await this.$http.post(
            "/user/login",
            this.loginForm
          );
          if (res.code == 200) {
            this.$message.success("登录" + res.msg);
            this.$router.push("/Home");
          } else {
            this.$message.error(res.msg);
          }
        });
      },

    }

  }

</script>

<style lang='less' scoped>
  .login_container {
    height: 100%;
    background-color: #0b3660;
  }

  .login_box {
    height: 300px;
    width: 450px;
    border-radius: 5px;
    background-color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
  }

  .login_form {
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 0 20px;
    box-sizing: border-box;
  }

  .btn {
    display: flex;
    justify-content: center;
  }

</style>
